<?php

class Model_home extends CI_Model
{
	function __construct()
	{
        parent::__construct();
	}
	
	function getFaq()
	{
		$this->db->select("*");
		$this->db->from('faq');
		$this->db->order_by("entry_date asc");
		$res = $this->db->get();
		if(($res->num_rows() > 0))
			return $res->result_array();
		else
			return array();
	}
	
	function getSystemVariable($field_name)
	{
		$this->db->select($field_name);
		$this->db->from('system_variable');
		$res = $this->db->get();
		if(($res->num_rows()>0))
			return $res->row_array();
		else
			return array();
	}
	
	function getbanner()
	{
		$this->db->select("*");
		$this->db->where("order_number >",'0');
		$res = $this->db->get('banner');
		if($res->num_rows() > 0)
			return $res->result_array();
		else
			return array();
	}
	
	function saveSystem($field,$value){
		$this->db->select("*");
		$this->db->from("system_variable");
		$query = $this->db->get();
		if($query->num_rows() == 0){
			$data = array(
			   $field => $value
			);
			$this->db->insert('system_variable', $data); 
		}else{
			$data = array(
			   $field => $value
			);			
			$this->db->update('system_variable', $data); 
		}
	}
	function addFAQ($question,$answer){
		$data = array(
		   'question' => $question ,
		   'answer' => $answer ,
		   'entry_date' => date("Y-m-d H:i:s")
		);
		
		$this->db->insert('faq', $data); 
	}
	function deleteFAQ($id){
		$this->db->where('id', $id);
		$this->db->delete('faq'); 
	}
	function is_unique_ip($ip_address){
		$this->db->from("polling");
		$this->db->where("ip_address",$ip_address);
		$query = $this->db->get();
		if($query->num_rows() == 0) return true;
		return false;
	}
	function addPolling($polling,$ip){
		$data = array(
		   'ip_address' => $ip ,
		   'polling_content' => $polling ,
		   'polling_date' => date("Y-m-d H:i:s")
		);
		$this->db->insert('polling', $data); 
	}
}
?>